<?php


namespace api\app\controller;


use api\web\model\BannerModel;
use api\app\model\DzModel;
use api\app\validate\DzValidate;
use cmf\controller\RestBaseController;

class DzController extends RestBaseController
{
    //查询内容，搜索名称
    public function getAddressList(){
        //分页
        $page = input('page/d',1);
        $pageSize = input('page_size/d',10);
        $list = DzModel::order('id','desc')
            ->field('id,user_name,mobile,area,address')
            ->page($page,$pageSize)
            ->select();
        $this->success('收货信息列表',$list);
    }
    //添加
    public function addAddress(){
        $data = input();
        //验证数据
        $validate = new DzValidate();
        $result = $validate->scene('add')->check($data);
        if(!$result){
            return error($validate->getError());
        }
        $add = DzModel::create($data);
        if($add){
            return success('添加成功');
        }
        return error('添加失败');
    }
    //修改更新数据
    public function editAddress(){
        $data = input();
        //验证数据
        $validate = new DzValidate();
        $result = $validate->scene('edit')->check($data);
        if(!$result){
            return error($validate->getError());
        }
        $edit = DzModel::where('id',$data['id'])->update($data);
        if($edit){
            return success('保存成功');
        }
        return error('保存失败');
    }
}